<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
/*
	[天生创想] (C)2008-2011 515158 Inc.
	This is NOT a freeware, use is subject to license terms
    URL:http://www.515158.com/
*/

get_config_keytable("office_document_".getGP('type','G')."");

empty($do) && $do = 'list';
if ($do == 'list') {
	//列表信息 
	$wheresql = '';
	$page = max(1, getGP('page','G','int'));
	$pagesize = 20;
	$offset = ($page - 1) * $pagesize;
	$url = 'admin.php?ac=index&fileurl=document';
		$wheresql .= " AND type = '".getGP('type','G')."'";
		$url .= '&type='.getGP('type','G');	
	if ($documentid = getGP('documentid','G')) {
		$wheresql .= " AND documentid like '%,".$documentid."%'";
		$url .= '&documentid='.$documentid;	
	}
	if(getGP('type','G')!='1'){
	if(!is_superadmin()){
	$wheresql .= "  and (readuser LIKE'%".GET_INC_USER_NAME($_USER->id)."%' or uid='".$_USER->id."' or readuser='全体人员')";
	}
	}else{
	$wheresql .= "  and uid='".$_USER->id."'";
	}
	
	
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."document WHERE 1 $wheresql");
     $sql = "SELECT * FROM ".DB_TABLEPRE."document WHERE 1 $wheresql ORDER BY id desc LIMIT $offset, $pagesize";
	$result = $db->fetch_all($sql);
    
	include_once('template/index.php');

} elseif ($do == '删 除') {
get_config_keytable("office_document_delete_".getGP('type','P')."");
	$idarr = getGP('id','P','array');
	foreach ($idarr as $id) {
	$db->query("DELETE FROM ".DB_TABLEPRE."workdate WHERE id = '$id'");
	//db->query("DELETE FROM ".DB_TABLEPRE."user_view WHERE uid = '$id'");
	$content=$id;
	$title='删除日程信息';
	get_oa_log_dbadd($id,$content,$title,10,$_USER->id);	
	}
	goto_page('admin.php?ac=index&fileurl=workdate&message=1');

} 



function get_document_list($fatherid=0,$selid=0,$layer=0)
{

    
    global $db;
	$query = $db->query("SELECT * FROM ".DB_TABLEPRE."document_type where father='$fatherid' and type='".$_GET[type]."' ORDER BY id Asc  ");
	
	if(count($query)>0){
	   //for($i=0;$i<$layer;$i++){
	   
	   //$str.="<TD class=MemoTD width=20>&nbsp;</TD>";
	   
	   //}
	while ($row = $db->fetch_array($query)) {
	$rsfno = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."document_type where father='".$row[id]."' and type='".$_GET[type]."' ORDER BY id desc limit 0,1");

	echo "a.add(".$row[id].",".$fatherid.",'".$row[title]."','admin.php?ac=index&fileurl=document&type=".$_GET[type]."&documentid=".$row[id]."');";

	if($rsfno[id]!=''){
	get_document_list($row['id'],$selid,$layer+1);
	}
	}
	}
	
   return ;

}
//读取文件夹
function GET_INC_document_type_USER_NAME($fid=0)
{
    global $db;
	$html='';
	$query = $db->query("SELECT title FROM ".DB_TABLEPRE."document_type where id='".$fid."' ORDER BY id desc limit 0,1");
	while ($rowuser = $db->fetch_array($query)) {
		$html .= $rowuser[title];
	}
	return $html;
}

?>